<?php

namespace App\Inventor\Controllers;

use App\Http\Controllers\Controller;
use App\Repositories\BaseApplyRepository;
use App\Services\BaseApplyService;
use App\Traits\BaseApplyTrait;


abstract class BaseApplyController extends Controller
{
    use BaseApplyTrait;

    protected $title;
    protected $description = ['default' => '申请前登记', 'grant' => '已授权'];
    public $repository;
    protected $service;

    public function __construct(BaseApplyRepository $repository, BaseApplyService $service)
    {
        $this->repository = $repository;
        $this->service = $service;
    }

    protected function grid($action)
    {
        $grid = $this->repository->userGrid();
        if ($action == 'grant') {
            $this->service->gridPublishColumns($grid);
        } else {
            $this->service->gridColumns($grid);
            $grid->model()->where('status', 0);
        }
        return $grid;
    }

    protected function form()
    {
        $form = $this->repository->form();
        $this->repository->formPublic($form);
        $this->service->formFields($form);
        return $form;
    }

}
